/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-06-24 17:09:54
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-06-28 14:57:24
 * @FilePath: /server/workspace/src/base/mutex.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"mutex.h"
namespace Yizhi
{
    Semaphore::Semaphore(uint32_t value){
        if(sem_init(&m_semaphore,0,value)!=0){
            throw std::runtime_error("Semaphroe initialization failed ");
        }
    }

    void Semaphore::wait(){
        if(sem_wait(&m_semaphore)!=0){
            throw std::logic_error("sem_wait error");
        }
    }

    void Semaphore::post(){
        if(sem_post(&m_semaphore)!=0){
            throw std::logic_error("sem_post error");
        }
    }


    Semaphore::~Semaphore(){
        sem_destroy(&m_semaphore);
    }



    
} // namespace Yizhi
